﻿package mortal.game.view.platform
{
    import com.mui.containers.globalVariable.*;
    import com.mui.controls.*;
    import fl.data.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.view.common.*;
    import mortal.mvc.core.*;

    public class PlatformVIPGiftCellRender extends GCellRenderer
    {
        private var _imgHuaWenLeft:GImageBitmap;
        private var _imgHuaWenRight:GImageBitmap;
        private var _itemList:GTileList;
        private var _canGetGiftBtn:GLoadingButton;
        private var _hasGetGiftBtn:GLoadingButton;
        private var _descTxt:GTextFiled;
        private var _giftData:PlatformVIPGiftGroup;

        public function PlatformVIPGiftCellRender()
        {
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            var _loc_2:String = null;
            super.data = param1;
            this._giftData = param1 as PlatformVIPGiftGroup;
            if (this._itemList)
            {
                this._itemList.dataProvider = this.getDataProviderByGiftCode(this._giftData.platformGift.reward);
                this._itemList.x = 54 + 108 - 34 + 19 + 106 - 0.5 * (this._itemList.dataProvider.length * 43);
                this._itemList.drawNow();
            }
            if (this._giftData.platformGift.pLv > 0)
            {
                _loc_2 = String(this._giftData.platformGift.pLv) + "级会员";
            }
            else if (this._giftData.platformGift.extend == 1)
            {
                _loc_2 = "年费会员";
            }
            EffectManager.glowFilterUnReg(this._canGetGiftBtn);
            this._canGetGiftBtn.filters = [];
            switch(this._giftData.receiveType)
            {
                case PlatformVIPGiftGroup.CanReceive:
                {
                    this.setCanGetStyle();
                    break;
                }
                case PlatformVIPGiftGroup.HasReceive:
                {
                    this.setHasGetStyle();
                    break;
                }
                default:
                {
                    this.setCanNotGetStyle();
                    break;
                    break;
                }
            }
            this._descTxt.text = _loc_2;
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._itemList.dispose(param1);
            this._itemList = null;
            this._canGetGiftBtn.dispose(param1);
            this._canGetGiftBtn = null;
            this._hasGetGiftBtn.dispose(param1);
            this._hasGetGiftBtn = null;
            this._descTxt.dispose(param1);
            this._descTxt = null;
            super.disposeImpl(param1);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.bg(9, 0, 662, 81, this, ImagesConst.LevelGiftBg));
            this.pushUIToDisposeVec(UIFactory.bg(505 + 16, 0, 2, 83, this, ImagesConst.VSplitLine));
            this._imgHuaWenLeft = UIFactory.gImageBitmap(ImagesConst.platform37WanGiftCellTxt, 120 - 40 + 60, 20 - 7, this);
            this._imgHuaWenRight = UIFactory.gImageBitmap(ImagesConst.platform37WanGiftCellTxt, 493 - 40 - 127 + 60, 22 - 7, this);
            this._imgHuaWenRight.scaleX = -1;
            this._itemList = UIFactory.tileList(260 - 32 - 24, 35, 500, 42, this);
            this._itemList.columnWidth = 50;
            this._itemList.rowHeight = 40;
            this._itemList.setStyle("cellRenderer", PlatformVIPItemCellRender);
            this._itemList.direction = GBoxDirection.HORIZONTAL;
            this._canGetGiftBtn = UIFactory.gLoadingButton(ResFileConst.ReceiveGiftBtn, 570 - 13, 70 - 36, 93, 30, this);
            this._canGetGiftBtn.configEventListener(MouseEvent.CLICK, this.onClickHandle);
            this._hasGetGiftBtn = UIFactory.gLoadingButton(ResFileConst.HasTakenBtn, 570 - 13, 70 - 36, 93, 30, this);
            this._hasGetGiftBtn.configEventListener(MouseEvent.CLICK, this.onClickHandle);
            this._hasGetGiftBtn.filterEnabled = false;
            this._descTxt = UIFactory.gTextField("", 300 - 36 - 27, 20 - 16, 260, 40, this, GlobalStyle.textFormatDangChen.setSize(14).setBold(true));
            return;
        }// end function

        private function onClickHandle(event:Event) : void
        {
            var _loc_2:* = PlatformGiftConfig.instance.getGift(this._giftData.platformGift.extend, this._giftData.platformGift.pLv).id;
            Dispatcher.dispatchEvent(new DataEvent(EventName.PlatformRequestVIPGift, _loc_2));
            return;
        }// end function

        private function setHasGetStyle() : void
        {
            this._canGetGiftBtn.visible = false;
            this._hasGetGiftBtn.visible = true;
            this._canGetGiftBtn.filterEnabled = false;
            this._canGetGiftBtn.drawNow();
            EffectManager.glowFilterUnReg(this._canGetGiftBtn);
            return;
        }// end function

        private function setCanGetStyle() : void
        {
            this._canGetGiftBtn.visible = true;
            this._hasGetGiftBtn.visible = false;
            this._canGetGiftBtn.filterEnabled = true;
            this._canGetGiftBtn.drawNow();
            EffectManager.glowFilterReg(this._canGetGiftBtn);
            return;
        }// end function

        private function setCanNotGetStyle() : void
        {
            this._canGetGiftBtn.visible = true;
            this._hasGetGiftBtn.visible = false;
            this._canGetGiftBtn.filterEnabled = false;
            this._canGetGiftBtn.drawNow();
            EffectManager.glowFilterUnReg(this._canGetGiftBtn);
            return;
        }// end function

        private function getDataProviderByGiftCode(param1:int) : DataProvider
        {
            var _loc_5:Array = null;
            var _loc_6:ItemData = null;
            var _loc_9:PlatformVIPItemGroup = null;
            var _loc_2:* = new DataProvider();
            var _loc_3:* = new ItemData(param1).itemInfo as ItemGiftBagInfo;
            var _loc_4:* = _loc_3.itemList1.split("&");
            var _loc_7:* = _loc_4.length;
            var _loc_8:int = 0;
            while (_loc_8 < _loc_4.length)
            {
                
                _loc_5 = _loc_4[_loc_8].split("#");
                _loc_9 = new PlatformVIPItemGroup();
                _loc_9.itemCode = int(_loc_5[1]);
                _loc_9.itemAmount = _loc_5[2];
                _loc_9.isBind = true;
                _loc_2.addItem(_loc_9);
                _loc_8++;
            }
            return _loc_2;
        }// end function

    }
}
